//
//  HomeApi.swift
//  Trill
//
//  Created by 顾钱想 on 2019/11/9.
//  Copyright © 2019 顾钱想. All rights reserved.
//

import Foundation
import Moya

enum HomeApi {
  //瀑布流
    case waterfall(position: Int, lastId: String)
}

extension HomeApi: TargetType {
    var baseURL: URL {
        return URL(string: Configs.Network.RootUrl)!
    }
    //https://api.gotokeep.com/feed/v1/feed/list?feedType=hot&needCommentInfo=1&needFavoriteInfo=1&needLikeInfo=1&needRelationInfo=1&position=0&sort=byTime
    var path: String {
        switch self {
        case .waterfall:
            return "feed/v1/feed/list"
        }
    }

    var method: Moya.Method{
        switch self {
        default:
            return .get
        }
    }

    var sampleData: Data {
         return "".data(using: String.Encoding.utf8)!
    }

    var task: Task {
        switch self {
//            let feedType: String = "hot"
//            let lastId: String
//            let needCommentInfo: Int = 1
//            let needFavoriteInfo: Int = 1
//            let needLikeInfo: Int = 1
//            let needRelationInfo: Int = 1
//            let position: Int
//            let sort: String = "byTime"
        case let .waterfall(position, lastId):
            return .requestParameters(parameters:[
            "feedType": "hot",
            "lastId": lastId,
            "needCommentInfo": 1,
            "needFavoriteInfo": 1,
            "needLikeInfo": 1,
            "needRelationInfo": 1,
            "position": position,
            "sort": "byTime"   ],
                                  encoding:  URLEncoding.default)
        }
        }
    var headers: [String : String]? {
        return nil
    }
}
